﻿#ifndef NEWTCPCLIENT_H
#define NEWTCPCLIENT_H

#include <QObject>
#include <QTcpSocket>
#include <QTimer>
#include "CommonDefine.h"
#include "ChosseVideo.h"
#include <QFileInfo>
#include "ChatTools/TransferProxy.h"

class NewTcpClient : public QObject
{
    Q_OBJECT
    //聊天内容
    QML_PROPERTY_(comInfo, QString,"")
    QML_PROPERTY_(transferProxy, TransferProxy*, nullptr)
public:
    //回复码
    enum ReplyCode {
        LoginSucceeded = 0,
        UnKonwError = -10001,
        //密码失败超过一定次数
        PasswordFailedMoreThanTimes = -10002,
        //账号不存在
        AccountNotExist = -10003,
        PasswordError = -10004,
        RegisterAccountExist = -10005,
        RegisterAccountSucceeded = 1,
    };

    //返回类型
    enum ReplyStatus {
        InfoMessage = 0,
        InfoImage,
        InfoMovie
    };

    using ptr = std::shared_ptr<NewTcpClient>;
    NewTcpClient();
    ~NewTcpClient();
    void            setClientSocket(QTcpSocket* ptr);
    QString         getAccount(){return mAccount;}
    QTcpSocket*     getTcpSocket(){return mClientSocket;}

public slots:
    //第二个参数为，是否把发出去的消息显示在消息框 默认是显示的
    void            sendMessageTClient(const QString& info, bool isDsplayText = true);
    void            disconnectServer();

private slots:
    void            readyReadySlot();
    void            disconnectSlot();
    //登录验证
    void            validateLogon(const QString& str);
    void            sendreply(QString head, int code, QString info = "None");
    void            registerAccount(const QString& str);

private:
    void            updataComInfo(QString message);

private:
    QTcpSocket*     mClientSocket = nullptr;
    //存放连接用户的账号
    QString         mAccount;
    bool            mIsConnectFlag = false;
};

#endif // NEWTCPCLIENT_H
